package com.leetcode.no496;

import javax.xml.stream.events.StartDocument;
import java.util.*;

public class Solution {
    public int[] nextGreaterElement(int[] nums1, int[] nums2) {
        int len1 = nums1.length;
        int len2 = nums2.length;

        if (len1 < 1 || len2 < 1 || len1 > len2) {
            return new int[]{};
        }

        int[] res = new int[len1];

        Stack<Integer> stack = new Stack<>();
        HashMap<Integer, Integer> map = new HashMap<>();

        stack.push(nums2[0]);
        // 右边数字入栈
        for (int j = 1; j < len2; j++) {
            int currNum = nums2[j];
            // 单调栈栈顶元素和当前数组元素作比较

            // 找到下一个更大元素
            while (!stack.isEmpty() && currNum >stack.peek()) {
                map.put(stack.pop(), currNum);
            }

            stack.push(currNum);
        }

        // 栈不为空 这些元素都是找不到下一个更大值的
        while (!stack.isEmpty()) {
            map.put(stack.pop(), -1);
        }

        for (int i = 0; i < len1; i++) {
            res[i] = map.get(nums1[i]);
        }
        return res;
    }

    public int[] nextGreaterElement01(int[] nums1, int[] nums2) {
        int len1 = nums1.length;
        int len2 = nums2.length;

        if (len1 < 1 || len2 < 1 || len1 > len2) {
            return new int[]{};
        }
        Stack<Integer> stack = new Stack<>();
        HashMap<Integer, Integer> map = new HashMap<>();
        int[] res = new int[nums1.length];

//        for(int i =0; i<len2; i++){
//
//        }
        return res;
    }
}
